package psd.model;

import java.util.ArrayList;
import java.util.List;


public class CompositeRule extends Rule {

	private List<Rule> rules = new ArrayList<Rule>();
	public List<Bug> execute() {
		List<Bug> compositeRuleBugs = new ArrayList<Bug>();
		boolean ruleSatisfied = true;
		for (Rule rule : rules) {
			List<Bug> ruleBugs = rule.execute();
			if (ruleBugs.size() == 0)
				ruleSatisfied = false;
			else
				compositeRuleBugs.addAll(ruleBugs);
		}
		
		List<Bug> compositeBugList = new ArrayList<Bug>();
		if(ruleSatisfied)
		{
			Bug compositeBug = new Bug();
			compositeBug.set_description(this.getDescription());
			compositeBug.set_lineNumber(compositeRuleBugs.get(0).get_lineNumber());
			compositeBug.set_path(compositeRuleBugs.get(0).get_path());
			compositeBug.set_priority(this.getPriority());
			compositeBugList.add(compositeBug);
		}
		
		return compositeBugList;
	}

}
